var UserId;
layui.config({
	version:'1510164124181'
}).use(['form', 'laypage', 'layer', 'element'],function(){
	form = layui.form;
	layer = layui.layer;
	$ = layui.jquery;
	laypage = layui.laypage;//分页
	element = layui.element; //元素操作
	UserId = GetQueryString("UserId");
	SelectRoleList();
	if(!isNotNull(UserId)){
		UserId=0;
	}else{
		SelectUserById();
	}
});
 function SelectUserById() {
	 $.ajax({
		 url: httpurl + "/findUserId",
		 cache: false,
		 headers: {
			 "Access-Control-Allow-Origin": "*",
			 "Access-Control-Allow-Methods": "*",
			 "Access-Control-Allow-Headers": "Authorization",
			 "Authorization": GetTokenInfo()
		 },
		 contentType : 'application/json',
		 data:{"id":UserId},
		 success: function (data) {
		 	// console.log(JSON.stringify(data));
		 	 let dataInfo=data.data;
			 $("#RoleList option[value='"+dataInfo.role.id+"']").attr("selected",true);//父级菜单id
			 $("#userAdmin").val(dataInfo.username);
			 $("#userPassword").val(dataInfo.password);
		 }
	 })
 };

function add_userinfo() {
	var roleId = $("#RoleList option:selected").val();
	var user_admin=$("#userAdmin").val();
	var user_password=$("#userPassword").val();
	if(roleId==0){
		layer.alert("请选择角色!!");
		return;
	}
	if(user_admin==""){
		layer.alert("请输入用户名!!");
		return;
	}
	if(user_password==""){
		layer.alert("请输入密码!!");
		return;
	}
	let httpAjax="updateUser";
	if(UserId==0){
		httpAjax="insertUser";
	}
	$.ajax({
		type: "POST",
		url: httpurl + "/"+httpAjax,
		cache: false,
		data: JSON.stringify({
			"id":UserId,
			"username":user_admin,
			"password":user_password,
			"roleid":roleId,
		}),
		headers: {
			"Access-Control-Allow-Origin": "*",
			"Access-Control-Allow-Methods": "*",
			"Access-Control-Allow-Headers": "Authorization",
			"Authorization": GetTokenInfo()
		},
		contentType : 'application/json',
		success: function (data) {
			console.log(JSON.stringify(data));
			layer.msg(data.msg);
			if(data.rtnCode==200){
				window.location.href="callAdmin.html";
			}
		},error:function (data) {
			layer.msg("读取接口失败,请稍后再试试");
	  }
	})
};

